// pages/cfp/cfp.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[
      
      
    ],
    introduce:'',
    showIntroduce:false,
    index:0,
    text:'欢迎光临~'
    

  },
  showDetails:function(e){
    var showIntroduce = this.data.showIntroduce;
    this.setData({
      showIntroduce:!showIntroduce
    });
    var index = e.currentTarget.dataset.index;
    console.log(index);
    var list = this.data.list;
    var introduce = list[index].introduce;
    this.setData({
      introduce:introduce
    })

  },
  goumai:function(e){
    var index = e.currentTarget.dataset.index;
    console.log(index);
    var list = this.data.list;
    if(app.globalData.player.money<list[index].price){
      this.setData({
        text:'你的钱不够哦~'
      })

    }else{
    var stock = list[index].stock;
    list[index].stock = stock - 1;
    this.setData({
      list:list,
      
    });
   
    var clothes = JSON.stringify(list[index]);
    
    console.log(clothes);

     wx.request({
      url: 'http://localhost:8080/buyClothes',
      method:'GET',
      data:{
        clothes:clothes

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        app.globalData.player = res.data;
        console.log(app.globalData.player);
        
      }
    })
  }
  },
  toggleDialog:function(){
    var array = ['欢迎光临~','今天进了许多新料子','店里的都是进来流行的式样'];
    var index = this.data.index;
    if(index==2){
      this.setData({
        index:0,
        text:array[0]
      })

    }
    else{
    this.setData({
      index:index+1,
      text:array[index+1]
    })
  }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/cfp',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          list:res.data
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})